<?php
// +----------------------------------------------------------------------
// | 通用PHP框架 [ ThinkPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 郑州智众 [Paulxun@qq.com]
// +----------------------------------------------------------------------
// | 官方网站: https://www.zzmind.com
// +----------------------------------------------------------------------

namespace app\cms\model;

use think\Model as ThinkModel;

/**
 * 滚动图片模型
 * @package app\cms\model
 */
class Slider extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $name = 'cms_slider';

    // 自动写入时间戳
    protected $autoWriteTimestamp = true;
	
	/**
	 * 获取栏目列表
	 * @author PaulXun <paulxun@qq.com>
	 * @return array|mixed
	 */
	public static function getList($cid = 1)
	{
	    $data_list = cache('slider_list');
	    if (!$data_list) {
	        $slider_list = self::where('status', 1)->where('cid', $cid)->order('sort')->select();
			$data_list = [];
			foreach ($slider_list as $key => $value) {
				$data_list[$key] = [
					'id' => $value['id'],
					'title' => $value['title'],
					'url'	=> $value['url'],
					'image'	=> get_file_path($value['cover']),
				];
			}
	        // 非开发模式，缓存数据
	        if (config('develop_mode') == 0) {
	            cache('slider_list', $data_list);
	        }
	    }
	    return $data_list;
	}
	
	/**
	 * 产品类型
	 * @param int $id 类型id
	 * @author paulxun
	 * @return array|static
	 */
	public static function column($id = 99)
	{
		$types = [
			1 => '门户首页',
			2 => '产品页',
			3 => '工作室页',
		];
	    if ($id === 99) {
	        $result = $types;
	    }else{
			$result = '';
			if(isset($types[$id])) $result = $types[$id];
		}
	    return $result;
	}
}
